package com.hexiang.rocketmq.mq.producer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class DelayTimeMessageProducer {

    private static final String TOPIC = "test_delay_time_spring_topic";

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    public void sendDelayTimeMsg(String msgBody) {
        SendResult sendResult = rocketMQTemplate.syncSend(TOPIC, MessageBuilder.withPayload(msgBody).build(), 3000, 3);
        // 通过sendResult返回消息是否成功送达
        log.warn("sendResult={} ", sendResult);
    }

}